<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<button type="button" id="btn_upCancel" class="btn btn-white">下载模板</button>
	<p>
		上传文件： <input id="file1" type="file" name="file" />
	</p>
	<input id="bbbbbbb" type="button" value="上传" />

	<script type="text/javascript"
		src="${pageContext.request.contextPath}/js/juqery.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath}/js/ajaxfileupload.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#btn_upCancel").click(function() {
				var url = "http://localhost:8080/demo/file/download.htm"; //   /** 使用ajaxFileUpload */
				$.ajaxFileUpload({
					url : url, //用于文件上传的服务器端请求地址
					dataType : 'json', //返回值类型 一般设置为json
					type : 'get'
				});
			});

			$("#bbbbbbb").click(
					function() {
						var formData = new FormData();

						formData.append("file", document
								.getElementById("file1").files[0]);
						$.ajax({
							url : "http://localhost:8080/demo/file/upload.htm",
							type : "POST",
							data : formData,
							contentType : false,//必须false才会自动加上正确的Content-Type  
							processData : false,//必须false才会避开jQuery对 formdata 的默认处理.XMLHttpRequest会对 formdata 进行正确的处理.  
							success : function(data) {
								console.log(data);
							},
							error : function(data) {
								alert("上传失败！" + data.Message);
							}
						});
					})
		});
	</script>
</body>
</html>